import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/web/yookassa/api_yookassa_transaction_revocation_info.dart';
import 'package:backend.purchases/infrastructure/dtos/api/api_money_amount_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/api_time_dto.dart';

const kApiYookassaTransactionRevocationInfoRefundedAmountKey = 'refunded_amount';
const kApiYookassaTransactionRevocationInfoTimeKey = 'time';

class ApiYookassaTransactionRevocationInfoDto extends Equatable {
  const ApiYookassaTransactionRevocationInfoDto._internal({
    required this.timeDto,
    required this.refundedAmountDto,
  });

  final ApiTimeDto timeDto;
  final ApiMoneyAmountDto refundedAmountDto;

  @override
  List<Object?> get props {
    return [
      timeDto,
      refundedAmountDto,
    ];
  }

  factory ApiYookassaTransactionRevocationInfoDto.fromEntity(
      ApiYookassaTransactionRevocationInfo revocationInfo) {
    final timeDto = ApiTimeDto.fromEntity(revocationInfo.time);
    final refundedAmountDto = ApiMoneyAmountDto.fromApiMoneyAmount(revocationInfo.refundedAmount);

    return ApiYookassaTransactionRevocationInfoDto._internal(
      timeDto: timeDto,
      refundedAmountDto: refundedAmountDto,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiYookassaTransactionRevocationInfoTimeKey: timeDto.toString(),
      kApiYookassaTransactionRevocationInfoRefundedAmountKey: refundedAmountDto.toJson(),
    };
  }
}
